/**
 * Copyright 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.google.api.adwords.starterkit.settings;

import com.google.api.adwords.starterkit.utils.AdTemplate;

import java.util.HashSet;

/**
 * The Class TextAdSettings keeps all settings related to TextAds.
 * 
 * @author rodrigo.f.vale@gmail.com (Rodrigo Vale)
 */
public class TextAdSettings {
  private boolean autoPause = false;
  private boolean syncStatus = true;
  private boolean autoCreation = true;
  private String displayUrl = "www.StarterKitDemo.com";
  private String destUrl = "http://www.StarterKitDemo.com";
  private HashSet<AdTemplate> adTemplates = new HashSet<AdTemplate>();

  /**
   * Instantiates a new text ad settings.
   * 
   * @param autoPause the auto pause
   * @param syncStatus the sync status
   * @param displayUrl the display url
   * @param destUrl the dest url
   * @param adTemplates the ad templates
   * @param autoCreation flag that allows starterkit to create new TextAds
   */
  public TextAdSettings(boolean autoPause, boolean syncStatus,
      String displayUrl, String destUrl, HashSet<AdTemplate> adTemplates,
      boolean autoCreation) {
    this.autoPause = autoPause;
    this.syncStatus = syncStatus;
    this.displayUrl = displayUrl;
    this.destUrl = destUrl;
    this.setAutoCreation(autoCreation);
    this.setAdTemplates(adTemplates);
  }

  public TextAdSettings() {

  }

  /**
   * Sets the auto pause.
   * 
   * @param autoPause the autoPause to set
   */
  public void setAutoPause(boolean autoPause) {
    this.autoPause = autoPause;
  }

  /**
   * Gets the auto pause.
   * 
   * @return the autoPause
   */
  public boolean getAutoPause() {
    return autoPause;
  }

  /**
   * Sets the sync status.
   * 
   * @param syncStatus the syncStatus to set
   */
  public void setSyncStatus(boolean syncStatus) {
    this.syncStatus = syncStatus;
  }

  /**
   * Gets the sync status.
   * 
   * @return the syncStatus
   */
  public boolean getSyncStatus() {
    return syncStatus;
  }

  /**
   * Sets the display url.
   * 
   * @param displayUrl the displayUrl to set
   */
  public void setDisplayUrl(String displayUrl) {
    this.displayUrl = displayUrl;
  }

  /**
   * Gets the display url.
   * 
   * @return the displayUrl
   */
  public String getDisplayUrl() {
    return displayUrl;
  }

  /**
   * Sets the dest url.
   * 
   * @param destUrl the destUrl to set
   */
  public void setDestUrl(String destUrl) {
    this.destUrl = destUrl;
  }

  /**
   * Gets the dest url.
   * 
   * @return the destUrl
   */
  public String getDestUrl() {
    return destUrl;
  }

  /**
   * Sets the ad templates.
   * 
   * @param adTemplates the adTemplates to set
   */
  public void setAdTemplates(HashSet<AdTemplate> adTemplates) {
    this.adTemplates = adTemplates;
  }

  /**
   * Clone the adtemplates hashset.
   * 
   * @return a new adTemplates hashSet
   */
  public HashSet<AdTemplate> cloneAdTemplates() {
    HashSet<AdTemplate> clonedAdTemplates = new HashSet<AdTemplate>();
    for (AdTemplate adTemplate : adTemplates) {
      AdTemplate clonedAdTemplate =
          new AdTemplate(adTemplate.getHead(), adTemplate.getLine1(),
              adTemplate.getLine2(), adTemplate.getTags(),
              adTemplate.getVisibleUrl(), adTemplate.getDestUrl());
      clonedAdTemplates.add(clonedAdTemplate);
    }
    return clonedAdTemplates;
  }

  /**
   * Gets the ad templates.
   * 
   * @return the ad templates
   */
  public HashSet<AdTemplate> getAdTemplates() {
    return cloneAdTemplates();
  }

  /**
   * @param autoCreation the autoCreation to set
   */
  public void setAutoCreation(boolean autoCreation) {
    this.autoCreation = autoCreation;
  }

  /**
   * @return the autoCreation
   */
  public boolean getAutoCreation() {
    return autoCreation;
  }
}